let v = new Vue({
    el:'#main-container',
    data:{
        emailInput:'form-inline',
        // email:'',
        user:{

        },
    },
    methods:{
        checkEmail:function () {
            let test = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
            if(test.test(this.user.email)){
                axios({
                    url:'checkEmail',
                    data:this.user.email,
                    method:'post'
                }).then(resp => {
                    if(!resp.data.success){
                        //没有这个邮箱
                        this.emailInput = 'form-inline has-error';
                    }else {
                        this.emailInput = 'form-inline';
                    }

                }).catch(error => {
                    layer.msg(error.message);
                })
            }else{
                this.emailInput = 'form-inline has-error';
                alert('邮箱格式不对！')
            }
        },
        sendCode:function () {
            axios({
                url:'code2Email',
                data:this.user.email,
                method:'post'
            }).then(resp => {
                layer.msg(resp.data.msg);
            }).catch(error => {
                layer.msg(error.message);
            })
        },
        resetPassword:function () {
            if(this.user.email == '' || this.user.email == undefined || this.user.password == '' || this.user.password == undefined ||
                this.user.loginCode == '' || this.user.loginCode == undefined){
                alert('信息不完整!');
            }else{
                axios({
                    url:'resetPassword',
                    data:this.user,
                    method:'post'
                }).then(resp => {
                    if(resp.data.success){
                        location.href = 'toIndex';
                    }else{
                        layer.msg(resp.data.msg);
                    }
                }).catch(error => {
                    layer.msg(error.message);
                })
            }
        }
    },
    created:function () {
        
    }
})